package com.qjdchina.sku.front.web.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.qjdchina.common.web.util.RestBody;
import com.qjdchina.commons.result.Result;
import com.qjdchina.sku.biz.SkuCompanyManager;
import com.qjdchina.sku.consts.WebConsts;
import com.qjdchina.sku.model.vo.SkuCompanyVO;
import com.qjdchina.sku.service.enums.SkuResultCode;

/**
 * 公司
 * @author shenpingfeng
 * 2017年1月5日
 */
@Controller
@RequestMapping(value = "company")
public class CompanyController {

	public static final Logger LOGGER = LoggerFactory.getLogger(CompanyController.class);
	@Autowired
	private SkuCompanyManager skuCompanyManager;

	/**
	 * 更新 
	 * shenpingfeng
	 * 2017年1月6日
	 * @param skuCompanyVO
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "update", method = RequestMethod.POST)
	@ResponseBody
	public RestBody<Integer> update(SkuCompanyVO skuCompanyVO,HttpServletRequest request) {
		skuCompanyManager.updateSkuCompany(skuCompanyVO);

		return new RestBody<Integer>(SkuResultCode.SUCCESS);

	}
	
	/**
	 * 查询 
	 * shenpingfeng
	 * 2017年1月6日
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "query", method = RequestMethod.GET)
	@ResponseBody
	public RestBody<SkuCompanyVO> query(Integer companyId,HttpServletRequest request) {
		HttpSession session = request.getSession();
		if(companyId == null){
			companyId = (Integer) session.getAttribute(WebConsts.COMPANY_ID);
		}
		if(companyId == null){
			return new RestBody<SkuCompanyVO>(SkuResultCode.USER_NOT_LOGIN);
		}
		Result<SkuCompanyVO> result = skuCompanyManager.findSkuCompanyByCompanyId(companyId);	

		return new RestBody<SkuCompanyVO>(SkuResultCode.SUCCESS,result.getDataModel());

	}

}
